import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Arrays;

public class Test {
        //数组：存放相同数据类型的集合
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5}; //静态初始化
        int[] array2 = new int[]{1,2,3,4,5};//通过new关键字来创建一个对象
        int[] array3 = new int[5];  //默认全为0
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(array[4]);//注意数组越界异常

        System.out.println(array.length);
        boolean[] array2 = new boolean[5];
        System.out.println(array2[3]);
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5};
        for (int i = 0; i < 5; i++) {
            System.out.println(array[i]);
        }
    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5};
        //foreach没有用到下标是和for的区别
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println();

        //为了更好的操作数组，提供了一系列的方法，Arrays
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        array[0] = 10;
        array[1] = 20;

        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;

        array = array2;
        array[2] = 300;
        array[3] = 400;
        array2[4] = 500;
    }

    public static void main6(String[] args) {
        int[] array = null;//空引用表示不指向任何对象
        System.out.println(array);
    }

    public static void func1(int[] array){
        array = new int[]{1,2,3};
    }
    public static void func2(int[] array){
        array[0] = 99;
    }

    public static void main(String[] args) {
        int[] array = {9,8,7};
        func1(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        System.out.println("=================");

        func2(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }

}
